import cv2
import numpy as np
#准备画板
img = np.zeros((500,700,3),dtype="u1")

#绘制直线+255实现白底
cv2.line(
    img,
    pt1=[10,10],
    pt2=[100,200],
    color =[0,0,255],
    thickness = 3,#线宽
    lineType = cv2.LINE_AA
)
#绘制矩形
cv2.rectangle(
    img,
    pt1 =[100,100],
    pt2 =[200,300],
    color =(255,0,0),
    thickness= -1,#填充
    lineType= cv2.LINE_AA
)
#绘制多边形
pts =np.array([
    [100,10],
    [100,200],
    [250,200]
],dtype =np.int32)
pts = pts.reshape(-1,1,2)#自动计算维度
print(pts)
print([pts])
cv2.polylines(
    img,
    pts=[pts],
    isClosed=True,
    color =(255,255,0),
    thickness = 3,#不能填充
    lineType = cv2.LINE_AA
)
#绘制椭圆
cv2.ellipse(
    img,
    center =(250,350),
    axes =(100,50),
    angle =0,
    startAngle = 30,
    endAngle = 360,
    color =(0,255,0),
    thickness=-1,
    lineType = cv2.LINE_AA
)
#绘制圆
cv2.circle(
    img,
    center=(400, 400),  # 圆心
    radius=50,  # 半径
    color=(0, 255, 255),
    thickness=-1,
    lineType=cv2.LINE_AA
)
#文本标注
cv2.putText(
    img,
    text="hqyj shanhai 25071",
    org =(400,20),
    fontFace= cv2.FONT_HERSHEY_TRIPLEX,
    fontScale=0.5,
    color=(0,0,0),
    bottomLeftOrigin=True
)
cv2.imshow("image",img)
cv2.waitKey(0)